package com.sls.game.dao.xinhe.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.sls.game.dao.impl.SuperDAO;
import com.sls.game.dao.xinhe.XinHeProductDAO;
import com.sls.game.page.Pagination;
import com.sls.game.pojo.xinhe.XinHeProduct;

@Repository("xinHeProductDAO")
public class XinHeProductDAOImpl extends SuperDAO<XinHeProduct> implements
		XinHeProductDAO {

	@Override
	public void insert(XinHeProduct product) {
		this.getSqlSession().insert("mybatis.xml.XinHeProductMapper.insert",
				product);
	}

	@Override
	public void update(XinHeProduct product) {
		this.getSqlSession().update("mybatis.xml.XinHeProductMapper.update",
				product);
	}

	@Override
	public XinHeProduct queryById(String id) {
		XinHeProduct pro = this.getSqlSession().selectOne(
				"mybatis.xml.XinHeProductMapper.selectByPrimaryKey", id);
		return pro;
	}

	@Override
	public XinHeProduct queryByProductId(String proId) {
		XinHeProduct pro = this.getSqlSession().selectOne(
				"mybatis.xml.XinHeProductMapper.queryByProductId", proId);
		return pro;
	}

	@Override
	public Pagination<XinHeProduct> queryPage(XinHeProduct product) {
		Pagination<XinHeProduct> paginationList = null;
		Integer rowCount = queryRowCount(product);

		product.calculate();
		List<XinHeProduct> list = queryGoodsInfoList(product);
		paginationList = this.queryPagination(rowCount, list, product);
		return paginationList;
	}

	@Override
	public List<XinHeProduct> queryAllXinHeInfo(XinHeProduct product) {
		List<XinHeProduct> list = this.getSqlSession().selectList(
				"mybatis.xml.XinHeProductMapper.queryAllXinHeInfo", product);
		return list;
	}

	/**
	 * 查询记录总数
	 * 
	 * @param enLinkGoodsInfo
	 * @return
	 */
	private Integer queryRowCount(XinHeProduct product) {
		Integer rowCount = this.getSqlSession().selectOne(
				"mybatis.xml.XinHeProductMapper.queryRowCount", product);
		return rowCount;
	}

	/**
	 * 记录结果集list
	 * 
	 * @param enLinkGoodsInfo
	 * @return
	 */
	private List<XinHeProduct> queryGoodsInfoList(XinHeProduct product) {
		List<XinHeProduct> list = this.getSqlSession().selectList(
				"mybatis.xml.XinHeProductMapper.queryXHProductInfoList",
				product);
		return list;
	}

}
